home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 05.zip / BS1 part 5 / IM_3.adf / Exec / piarc.LZH / DHRZRDR.rexx < prev    next >
OS/2 REXX Batch file  |  1992-02-29  |  6KB  |  240 lines

  1. /*
  2.  * dhrzr.rexx
  3.  *
  4.  *  Written by: Pete Patterson & Ben Williams
  5.  * Last Update: January 17, 1992
  6.  *         For: Black Belt Systems image processing series IM, IM F/c, and IP.
  7.  * ---------------------------------------------------------------------------
  8.  *    Revision: 1.01
  9.  */
  10.  
  11. /*
  12.  * open rexxsupport.library -- needed for some functions
  13.  */
  14. if ~show('L',"rexxsupport.library") then do
  15.   if addlib('rexxsupport.library',0,-30,0) then do
  16.       /* everything's ok */
  17.     end;
  18.   else do
  19.     say 'We Have A Library Problem, Unable To Load "rexxsupport.library"';
  20.     say 'Cannot operate dhrzr.rexx without this library - sorry!';
  21.     exit 10;
  22.     end;
  23.   end;
  24.  
  25. /*
  26.  * This will automatically direct the script to the proper
  27.  * software, if it is running.
  28.  */
  29. prtnme = 'IP_Port'; /* assume Image Professional */
  30. if show('P','IP_Port') = 0 then do
  31.   if show('P','IM_Port') = 0 then do
  32.     say "Can't find image processor's ARexx port!!!"; /* not running? */
  33.     say "This script requires IP, IM or IM F/c to run!";
  34.     exit(20);
  35.     end;
  36.   else do
  37.     prtnme = 'IM_Port'; /* That's the thing about assumptions... */
  38.     end;                 /* We make em, user's break em.          */
  39.   end;
  40.  
  41.   /*
  42.    * This code attempts to read a file called "picmdpath" from REXX:
  43.    * If it can't find it, the script will assume that the commands
  44.    * associated with this PI Module are in "c:". If the file exists,
  45.    * the script will look in the path that is specified in the file.
  46.    * If you create this file, you MUST put a complete, correct path
  47.    * in it; if the commands are in a sub-directory, you have to put
  48.    * the trailing slash on the path (like, device:dir/).
  49.    * 
  50.    */
  51.   cmdpath = 'c:';
  52.   if open(fhandle,'rexx:picmdpath','read') then  /* open the file */
  53.     do
  54.       cmdpath = readln(fhandle);
  55.       call close(fhandle);  /* close the file    */
  56.     end
  57.  
  58. options;
  59. address;
  60.  
  61.   prevpath = 'ram:'; /* put user in ram to start with... */
  62.  
  63.   if show('C',dhrzpath) = 1 then do
  64.     prevpath = getclip(dhrzpath);
  65.     end;
  66.  
  67.   address(prtnme);
  68.   options results;
  69.   'current';
  70.   bufdata = result; /* get name of buffer, if there is one */
  71.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum;
  72.   if bname ~= '<none>' then do
  73.     bufname = bname;
  74.     end;
  75.   if (length(bufname) > 4) then do
  76.     epos = pos('.dhrz',bufname,length(bufname)-4);
  77.     if epos ~= 0 then do
  78.       bufname = left(bufname,epos-1)
  79.       end
  80.     end;
  81.   'filerequest "'||prevpath||'","'||bufname||'",".dhrz","Load dhrz"';
  82.   dhrzfile = result;
  83.   options;
  84.  
  85.   if dhrzfile = 'FR_CANCELLED' then do
  86.     address(prtnme);
  87.     'imtofront';
  88.     exit 0;
  89.     end;
  90.  
  91.   dhrzfile = expandfilename(dhrzfile);
  92.   thispath = gimmepath(dhrzfile);
  93.   call setclip(dhrzpath,thispath);
  94.  
  95.   address command cmdpath||'DHRZRD c "'||dhrzfile||'"';
  96.   if rc ~= 0 then do
  97.     address(prtnme);
  98.     'message "Cannot read '||dhrzfile||' Error '||rc||'"';
  99.     exit 0; /* this is not a proper dhrz file */
  100.     end;
  101.  
  102.   call open(fhandle,'ram:IP_LDDHRZ.tmp','read');      /* open the file */
  103.   rstring = readln(fhandle);
  104.   call close(fhandle);                     /* close the file    */
  105.   
  106.   address command 'c:delete >nil: ram:IP_LDDHRZ.tmp';
  107.   
  108.   parse var rstring width '/' height
  109.  
  110.   if height < 0 then do
  111.     'message "Bad Height: '||height||'"';
  112.     exit 0;
  113.     end;
  114.  
  115.   if height > 32767 then do
  116.     'message "Bad Height: '||height||'"';
  117.     exit 0;
  118.     end;
  119.  
  120.   if width < 0 then do
  121.     'message "Bad Width: '||width||'"';
  122.     exit 0;
  123.     end;
  124.  
  125.   if width > 32767 then do
  126.     'message "Bad Width: '||width||'"';
  127.     exit 0;
  128.     end;
  129.  
  130.   address(prtnme);
  131.   
  132.   'imtofront'; /* show user the IM screen */
  133.   /* is there already a primary buffer??? */
  134.   options results;
  135.   'current';
  136.   bufdata = result;
  137.   options;
  138.  
  139.   parse var bufdata bname ',' bnum ',' bx ',' by ',' btot ',' bmem ',' bparname ',' bparnum
  140.   if bname ~= '<none>' then do
  141.     address(prtnme);
  142.   options results;
  143.   'askyn '||'"Replace Primary ['||bname||']" "New As Primary"'
  144.   prefs = result;
  145.   options;
  146.   address;
  147.   if prefs = 0 then do
  148.     address(prtnme);
  149.     'killbuff '||bnum; /* this kills the Primary Buffer */
  150.     address;
  151.     end;
  152.   end;
  153.  
  154.   /* New buffer is created at current resolution */
  155.   address(prtnme);
  156.   'autoredraw 0';
  157.   options results;
  158.   'newbuf '||width||' '||height;
  159.   if rc ~= 0 then do
  160.     "message Can't allocate buffer!";
  161.     'autoredraw 1';
  162.     exit 0;
  163.     end
  164.   bnum = result;
  165.   options;
  166.   'newcurrent '||bnum;
  167.   'rename '||bnum||' 'gxname;
  168.   'autoredraw 1';
  169.   address;
  170.  
  171.   address(prtnme);
  172.   options results;
  173.   'jackin';
  174.   jackadr = result;
  175.   options;
  176.  
  177.   'wbtofront';
  178.   'lockimage '||bnum;
  179.   address command cmdpath||'DHRZRD d'||jackadr||' "'||dhrzfile||'"';
  180.   'unlockimage '||bnum;
  181.  
  182.   address(prtnme);
  183.   'imtofront';
  184.   'redraw';
  185.   address;
  186.  
  187.   exit 0;
  188.  
  189. /*
  190.  * gimmepath
  191.  *
  192.  * This takes the provided argument and sucks the path out of it, then
  193.  * returns that path to the caller, sans file name.
  194.  */
  195. gimmepath:
  196.   arg fullnamegx;
  197.     tempgx = reverse(fullnamegx);
  198.     lengx = length(fullnamegx);   /* get length of string */
  199.     slashdex = index(tempgx,'/'); /* first occurance of '/' from right */
  200.     colondex = index(tempgx,':');  /* first occurance of ':' from right */
  201.     seploc = 0; /* assumes current dir, no path supplied */
  202.     if slashdex ~= 0 then do /* we assume we are in a DIR */
  203.       seploc = (lengx - slashdex)+1;
  204.       end;
  205.     else do
  206.       if colondex ~= 0 then do /* we assume we are on a device */
  207.         seploc = (lengx - colondex)+1;
  208.         end;
  209.       end;
  210.   gxname = substr(fullnamegx,seploc+1); /* if you ever need it */
  211.   gxpath = left(fullnamegx,seploc);
  212.   return(gxpath);
  213.  
  214. /*
  215.  * Since this script can't be expected to know where the CD of the user
  216.  * is when this cmd is invoked, we have to check the path the user
  217.  * provides - if it's not specified right from a root, then we have
  218.  * to make it a complete specification from the root.
  219.  */
  220. expandfilename:
  221.   parse arg jfile;
  222.   if index(jfile,':') = 0 then do
  223.     curdir = pragma(D);
  224.     if right(curdir,1) ~= ':' then do
  225.       if right(curdir,1) ~= '/' then do
  226.         if curdir ~= '' then do
  227.           curdir = curdir || '/';
  228.           end;
  229.         end;
  230.       end;
  231.     jfile = curdir||jfile;
  232.     end;
  233.   return(jfile);
  234.  
  235. rvalue:
  236.   wordnum = c2d(readch(fhandle,1)) * 256;
  237.   wordnum = wordnum + c2d(readch(fhandle,1));
  238.   return wordnum;
  239.  
  240.